package cn.itcast.cd.query;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class Query extends BaseQuery{

	private String keyWords;
	private Double minSalary;
	private Double maxSalary;

	
	public String getKeyWords() {
		return keyWords;
	}
	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}
	public Double getMinSalary() {
		return minSalary;
	}
	public void setMinSalary(Double minSalary) {
		this.minSalary = minSalary;
	}
	public Double getMaxSalary() {
		return maxSalary;
	}
	public void setMaxSalary(Double maxSalary) {
		this.maxSalary = maxSalary;
	}
	@Override
	public String toString() {
		return "Query [keyWords=" + keyWords + ", minSalary=" + minSalary
				+ ", maxSalary=" + maxSalary + "]";
	}
	
	public List getConditions(){
		if(StringUtils.isNotBlank(keyWords)){
			conditions.add(" AND obj.name like ?");
		}
		if(minSalary!=null){
			conditions.add(" AND obj.salary >= ?");
		}
		if(maxSalary!=null){
			conditions.add(" AND obj.salary <= ?");
		}
		return conditions;
	}
	
	public Object[] getParams(){
		if(StringUtils.isNotBlank(keyWords)){
			params.add("%"+keyWords+"%");
		}
		if(minSalary!=null){
			params.add(minSalary);
		}
		if(maxSalary!=null){
			params.add(maxSalary);
		}
		System.out.println(params);
		return params.toArray();
	}
}
